unit FActiveX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,ComObj, AxCtrls, ActiveX,FAXClass_TLB;

type
  TFormFActiveX = class(TActiveForm)
  private
    { Private declarations }
    FEvents: IActiveFormXEvents;
  protected
    procedure InitLibrary; virtual;
    procedure DestroyLibrary; virtual;
    procedure InitActiveForm; virtual;
    procedure DestroyActiveForm; virtual;

    procedure EventSinkChanged(const EventSink: IUnknown); override;
    property Events: IActiveFormXEvents read FEvents write FEvents;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Initialize; override;
    function DoEvent(AEventName: String; AInParams: OleVariant): OleVariant;
  end;

var
  FormLibraryCount: Integer;
  AutoLibraryCount: Integer;

implementation

{$R *.dfm}

{ TFormFActiveX }

constructor TFormFActiveX.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

end;

destructor TFormFActiveX.Destroy;
begin
  DestroyActiveForm;
  Dec(FormLibraryCount);
  if FormLibraryCount = 0 then
    DestroyLibrary;
  inherited Destroy;
end;

procedure TFormFActiveX.DestroyActiveForm;
begin

end;

procedure TFormFActiveX.DestroyLibrary;
begin

end;

function TFormFActiveX.DoEvent(AEventName: String;
  AInParams: OleVariant): OleVariant;
var
  i, iHigh: Integer;
  InParams: OleVariant;
begin
  if FEvents <> Nil then
  begin
    if VarIsArray(AInParams) then
      iHigh := VarArrayHighBound(AInParams, 1)
    else if (Not VarIsNull(AInParams)) and (Not VarIsClear(AInParams)) then
      iHigh := 0
    else
      iHigh := -1;
    Inc(iHigh);
    InParams := VarArrayCreate([0, iHigh], varVariant);
    InParams[0] := AEventName;
    For i := 1 To iHigh Do begin
      if VarIsArray(AInParams) then
        InParams[i] := AInParams[i - 1]
      else if (Not VarIsNull(AInParams)) and (Not VarIsClear(AInParams)) then
        InParams[i] := AInParams;
    end;
    FEvents.OnEvent(InParams, Result);
  end;
end;

procedure TFormFActiveX.EventSinkChanged(const EventSink: IInterface);
begin
  FEvents := EventSink as IActiveFormXEvents;
  inherited EventSinkChanged(EventSink);

end;

procedure TFormFActiveX.InitActiveForm;
begin

end;

procedure TFormFActiveX.Initialize;
begin
  inherited Initialize;
  if FormLibraryCount = 0 then
    InitLibrary;
  Inc(FormLibraryCount);
  InitActiveForm;

end;

procedure TFormFActiveX.InitLibrary;
begin

end;

end.
